#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 5;
const int M = 1e6 + 5;

struct seg {int l, r; } h[N];

int T, _T, n, m, L, V, d[N], v[N], a[N], p[N];
int tot, res, cnt, lb[N], rb[N], t[M];

bool cmp1 (seg x, seg y) { return x.l != y.l ? x.l < y.l : x.r < y.r; }

int findL (int x) {
    int res, l = 1, r = m;
    while (l <= r) {
        int mid = l + r >> 1;
        if (x <= p[mid]) res = mid, r = mid - 1;
        else l = mid + 1;
    }
    return res;
}

int findR (int x) {
    int res, l = 1, r = m;
    while (l <= r) {
        int mid = l + r >> 1;
        if (x >= p[mid]) res = mid, l = mid + 1;
        else r = mid - 1;
    }
    return res;
}

void work () {
    cin >> n >> m >> L >> V;
    for (int i = 1; i <= n; i++)
        cin >> d[i] >> v[i] >> a[i];
    for (int i = 1; i <= m; i++)
        cin >> p[i];

    tot = cnt = res = 0;
    memset (t, 0, sizeof t);
    for (int i = 1; i <= n; i++) {
        if (d[i] > p[m])
            continue;
        if (a[i] == 0) {
            if (v[i] > V) {
                lb[++tot] = d[i];
                rb[tot] = L;
            }
        } else if (a[i] < 0) {
            if (v[i] > V) {
                lb[++tot] = d[i];
                rb[tot] = (v[i] * v[i] - V * V - 2 * a[i] - 1) / (-2 * a[i]) + d[i] - 1;
                rb[tot] = min (rb[tot], L);
            }
        } else {
            if (v[i] > V) {
                lb[++tot] = d[i];
                rb[tot] = L;
            } else {
                lb[++tot] = (V * V - v[i] * v[i]) / (2 * a[i]) + d[i] + 1;
                rb[tot] = L;
                if (lb[tot] > L) --tot;
            }
        }
    }
    for (int i = 1; i <= m; i++) {
        t[p[i]]++;
        t[p[i] + 1]--;
    }
    for (int i = 1; i <= L; i++) t[i] += t[i - 1];
    for (int i = 1; i <= L; i++) t[i] += t[i - 1];
    for (int i = 1; i <= tot; i++) {
        int tmp = t[rb[i]];
        if (lb[i] > 0) tmp -= t[lb[i] - 1];
        if (tmp) {
            cnt++;
            h[cnt].l = findL (lb[i]);
            h[cnt].r = findR (rb[i]);
        }
    }
    sort (h + 1, h + cnt + 1, cmp1);
    int cur = -1;
    for (int i = 1; i <= cnt; i++) {
        if (cur < h[i].l) {
            cur = h[i].r;
            ++res;
        } else if (cur > h[i].r)
            cur = h[i].r;
    }
    cout << cnt << ' ' << m - res << '\n';
}

signed main() {
    ios::sync_with_stdio (0);
    cin.tie (0);
    cout.tie (0);

    freopen ("detect.in", "r", stdin);
    freopen ("detect.out", "w", stdout);

    cin >> T;
    for (_T = 1; _T <= T; _T++) work ();

    return 0;
}
